import { downloadCheck } from 'S/order';
export function multiDownLoad(val, baseUrl, type, keyObg, callBack) {
    download(0, val, baseUrl, type, keyObg, callBack);
}
async function download(i, val, baseUrl, type, keyObg, callBack) {
    if (i < val.length) {
        let res = await downloadCheck({ productId: val[i][keyObg.id] });
        if (res.status === 200) {
            if (res.data) {
                const iframe = document.createElement('iframe');
                iframe.style.display = 'none';
                iframe.style.height = 0;
                if (val[i] && (val[i].url || val[i][keyObg.url])) {
                    iframe.src = baseUrl + 'public/down?url=' + (val[i].url || val[i][keyObg.url]);
                    document.body.appendChild(iframe);
                    setTimeout(res => {
                        iframe.remove();
                    }, 5 * 60 * 1000);
                }
                i++;
                download(i, val, baseUrl, type, keyObg, callBack);
            } else {
                if (callBack) {
                    callBack();
                }
            }
        }
    }
}
